<template>
  <div class="dashboard-editor-container">
    <panel-group
      ref="panelGroup"
      :countList="countList"
      @handleSetLineChartData="handleSetLineChartData" />

    <el-row :gutter="32">
      <el-col :span="12" >
        <div class="chart-wrapper">
          <pie-template-chart ref="pipTemplateChart" />
        </div>
      </el-col>
      <el-col :span="12" >
        <div class="chart-wrapper">
          <pie-push-user-chart ref="pipPushUserChart" />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import PanelGroup from '@/views/cps/controllerData/component/PanelGroup.vue'
import PieTemplateChart from '@/views/cps/controllerData/component/PieTemplateChart.vue'
import PiePushUserChart from '@/views/cps/controllerData/component/PiePushUserChart.vue'
import {getCpsCount, getEquipmentRelateWarning} from "@/api/home/home-api";

export default {
  name: 'index',
  components: {
    PanelGroup,
    PieTemplateChart,
    PiePushUserChart
  },
  data() {
    return {
      lineChartData: {},
      countList: [], // 头部数据
      productREquipmentList: [], // 产品关联设备统计
      equipmentRelateWarningList: [], // 设备关联告警统计
    }
  },
  async mounted() {
    await getCpsCount().then(res => {
      const data = res.data
      this.countList.productEnabelCount = data.productEnabelCount
      this.countList.productDisableCount = data.productDisableCount
      this.countList.equipmentEnableCount = data.equipmentEnableCount
      this.countList.equipmentDisableCount = data.equipmentDisableCount
      this.countList.equipmentCount = data.equipmentCount
      this.countList.productCount = data.productCount
      this.productREquipmentList = data.productREquipmentCount
    })
    await getEquipmentRelateWarning().then(res => {
      this.equipmentRelateWarningList = res.data
    })

    this.$refs.panelGroup.init(this.countList)
    this.$refs.pipTemplateChart.initChart(this.productREquipmentList)
    this.$refs.pipPushUserChart.initChart(this.equipmentRelateWarningList)
  },
  methods: {
    handleSetLineChartData(type) {
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}


</style>
